package com.engine4cloud.tdf.supervision.convert;

import com.engine4cloud.tdf.common.security.service.TdfUser;
import com.engine4cloud.tdf.supervision.dto.InvAuditDTO;
import com.engine4cloud.tdf.supervision.dto.create.DcpgAuditCreateDTO;
import com.engine4cloud.tdf.supervision.dto.result.DcpgAuditResultDTO;
import com.engine4cloud.tdf.supervision.dto.update.DcpgAuditDepartUpdateDTO;
import com.engine4cloud.tdf.supervision.entity.DcpgAuditResultEntity;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.time.LocalDateTime;

@Mapper
public interface DcpgAuditResultConvert {
    DcpgAuditResultConvert INSTANCE = Mappers.getMapper(DcpgAuditResultConvert.class);

    DcpgAuditResultDTO convert(DcpgAuditResultEntity entity);

    DcpgAuditResultEntity create(DcpgAuditCreateDTO entity);

    default DcpgAuditResultEntity create(DcpgAuditCreateDTO dto, InvAuditDTO audit, TdfUser user) {
        //设置调查结果主信息
        DcpgAuditResultEntity entity = DcpgAuditResultConvert.INSTANCE.create(dto);
        //设置状态
        entity.setShjg(audit.getStatus());
        //设置说明
        entity.setShsm(dto.getShsm());
        //审核人
        entity.setShry(user.getUsername());
        //审核时间
        entity.setShsj(LocalDateTime.now());
        //设置部门
        entity.setPreDeptId(audit.getPreDeptId());
        //设置租户id
        entity.setTenantId(user.getTenantId());
        return entity;
    }

    /**
     * @param code   调查评估编号
     * @param deptId 部门id
     * @return DcpgAuditDepartUpdateDTO
     */
    default DcpgAuditDepartUpdateDTO update(String code, Long deptId) {
        DcpgAuditDepartUpdateDTO update = new DcpgAuditDepartUpdateDTO();
        update.setDcpgbh(code);
        update.setDeptId(deptId);
        return update;
    }

}
